package Java8.Test;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @time: 2021/10/9/009 10:46
 * @author: Zhurunhe
 * @Version：1
 */
public class StreamDemo {
    public static void main(String[] args) {
        List<Person> personList = new ArrayList<Person>();
//        personList.add(new Person("Tom", 8900, 10,"male", "New York"));
//        personList.add(new Person("Jack", 7000, 20,"male", "Washington"));
//        personList.add(new Person("Lily", 7800, 22,"female", "Washington"));
//        personList.add(new Person("Anni", 8200, 24,"female", "New York"));
//        personList.add(new Person("Owen", 9500, 11,"male", "New York"));
//        personList.add(new Person("Alisa", 7900, 10,"female", "New York"));

        //foreach（遍历）/find/match
//        personList.stream().filter(item->item.getAge()>10).forEach(System.out::println);
//        personList.stream().filter(item->item.getName().equals("Owen")).findAny();
        //按年龄进行降序
//        List<Person> collect = personList.stream().sorted(Comparator.comparing(Person::getAge).reversed().thenComparing(Person::getSalary)).collect(Collectors.toList());

//        collect.stream().forEach(System.out::println);

     /*   Set<String> set=new HashSet<>();
        set.add("1");
        set.add("1");
        set.add("2");
        System.out.println(set);*/
        List<Map<String, Object>> mapList=new ArrayList<>();
        Map<String,Object> map1=new HashMap<>();
        Map<String,Object> map2=new HashMap<>();
        Map<String,Object> map3=new HashMap<>();
        Map<String,Object> map4=new HashMap<>();
        Map<String,Object> map5=new HashMap<>();
        map4.put("id",1);
        map1.put("id",4);
        map3.put("id",3);
        map2.put("id",2);
        map5.put("id",5);
        mapList.add(map4);
        mapList.add(map1);
        mapList.add(map3);
        mapList.add(map2);
        mapList.add(map5);
        mapList=mapList.stream().sorted(Comparator.comparing(e -> Integer.valueOf(e.get("id").toString()))).collect(Collectors.toList());
        System.out.println(mapList);
    }

}




class Person {
    private String name;  // 姓名
    private int salary; // 薪资
    private int age; // 年龄
    private String sex; //性别
    private String area;  // 地区

    // 构造方法
    public Person(String name, int salary, int age,String sex,String area) {
        this.name = name;
        this.salary = salary;
        this.age = age;
        this.sex = sex;
        this.area = area;
    }
// 省略了get和set，请自行添加

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getSalary() {
        return salary;
    }

    public void setSalary(int salary) {
        this.salary = salary;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public String getArea() {
        return area;
    }

    public void setArea(String area) {
        this.area = area;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", salary=" + salary +
                ", age=" + age +
                ", sex='" + sex + '\'' +
                ", area='" + area + '\'' +
                '}';
    }
}
